var app = getApp() 
var pageObject = {
  data: {
    product: {},
    imgUrls: [],
    indicatorDots: true,
    countdown: 60,
    user: '',
    autoplay: true,
    interval: 5000,
    duration: 400,
    modalState: false,
    inputPhoneNumber: '',
    hasSend: false,
    shop_id: '',
    product_id: '',
    inputCaptcha: ''
  },
  onLoad: function(options) { 
    this.getProductInfo(options);
  },
  buyBtnEvent: function(event) {
    wx.redirectTo({
      url: '../order-confirm/order-confirm?productId=' + event.currentTarget.dataset.id + '&nums=1'
    })
  }, 
  countDownEvent: function() {
    var _this = this
    var sendPhoneCodeInterval = setInterval(function() {
      if (_this.data.countdown == 0) {
        clearInterval(sendPhoneCodeInterval)
        _this.setData({
          countdown: 60,
          hasSend: false
        })
      } else {
        _this.setData({
          countdown: _this.data.countdown - 1
        })
      }
    }, 1000)
  }, 
  getProductInfo: function(options) {
    var _this = this; 
    wx.request({ 
      url: app.globalData.product_detail_url,
      data: {
        id : options.id
      },
      method: 'GET', 
      success: function (res) {
        var resultData = res.data;
        if(resultData.errno==0){ 
          _this.setData({ 
            product:resultData.data,
          })
        }
      },
      fail: function () {
        setTimeout(function () {
          wx.showToast({
            title: "加载失败"
          })
        }, 100)
      }
    }) 
  }, 
  
}

Page(pageObject)
